
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex);

//使用vuex
export default new Vuex.Store({//创建仓库
  //定义公共的数据
   state:{
     city:  localStorage.city || "马泉营"
   },
   actions : {
     changeCity (ctx,city) {
      // console.log(city);
       ctx.commit('changeCity',city);//需要调用mutations来改变公共的数据
     }
   },
  mutations :{
     changeCity (state,city){
       state.city=city;
       localStorage.city=city;//本地存储
     }
  }

})
